'''
this script defined a serious of functions about time,date etc.
create at: 2013.5.21
author: lifengya@kingsoft.com
>>> 
>>> from mytime import getToday,getYesterday,getHour,getMin
>>> print time.localtime()
time.struct_time(tm_year=2013, tm_mon=5, tm_mday=21, tm_hour=11, tm_min=25, tm_sec=17, tm_wday=1, tm_yday=141, tm_isdst=0)
>>> print getToday()
20130521
>>> print getYesterday()
20130520
>>> print getHour()
11
>>> print getMin()
25
>>> 
'''

import time
import re

def getToday():
	return time.strftime('%Y%m%d')

def getYesterday():
	secondsNow = time.time()
	secondsYesterday = secondsNow - 24 * 60 * 60
	YestLocaltime = time.localtime(secondsYesterday)
	YestDate = time.strftime('%Y%m%d',YestLocaltime)
	return YestDate

def getHour():
	return time.strftime('%H')

def getMin():
	return time.strftime('%M')

def checkDate(date):
	if date is not None:
		datePartern = '^\d{8}$'
		if re.match(datePartern,date):
			return date
		else:
			raise Exception ('FATAL: Wrong date format: %s .supposed to be "yyyymmdd" ') % (date)

def getHourlist():
	hourList = ['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23']
	return hourList
	



